package com.hw.dagl.service.impl;

import com.hw.dagl.model.Frm_Code;
import com.hw.dagl.service.CodeService;
import com.hw.dao.utils.EntityTools;
import com.hw.dao.utils.OraclePageDaoBase;

import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2015/12/24.
 */
@Service
public class CodeServiceImpl implements CodeService {

    @Resource
    private OraclePageDaoBase oraclePageDaoBase;

    /* 
     * 查询字典表
     */
    @Override
    public List<Frm_Code> findCodeByCodetype(String dmlb,String xtlb) {
        List<Frm_Code> list = null;
        String sql = " select t.*,t.dmz||':'||t.dmsm1 as dmsm1mc from Frm_Code t where 1=1 ";
        List<Object> args = new ArrayList<>();
        if (StringUtils.isNotEmpty(dmlb)) {
            sql+=" and t.dmlb=? ";
            args.add(dmlb);
        }
        if (StringUtils.isNotEmpty(xtlb)) {
            sql+=" and t.xtlb=? ";
            args.add(xtlb);
        }
        sql+=" order by t.dmz ";
        list =  oraclePageDaoBase.query(sql,args.toArray(), new RowMapper<Frm_Code>(){
            private EntityTools<Frm_Code> pc = new EntityTools<Frm_Code>();
            @Override
            public Frm_Code mapRow(ResultSet rs, int index)throws SQLException {
                Frm_Code sp = new Frm_Code();
                pc.setColumnsValueByResultSet(rs, sp);
                return sp;
            }
        });
        return list;
    }
   
}
